package me.lc.linklink.scene;

import me.lc.linklink.core.GameManager;
import me.lc.linklink.core.StageManager;
import me.lc.linklink.layer.GameBGLayer;
import me.lc.linklink.layer.GameLayer;
import me.lc.linklink.util.ADHelper;
import me.lc.linklink.util.GameUtil;
import android.view.KeyEvent;

import com.wiyun.engine.nodes.Scene;
import com.wiyun.game.WiGame;
import com.wiyun.game.model.ChallengeRequest;

public class GameScene extends Scene {

	private static GameScene instance = null;
	private static Object sync_obj = new Object();

	GameLayer gameLayer;

	protected GameScene() {
		gameLayer = new GameLayer();
		gameLayer.setTouchEnabled(true);
		addChild(new GameBGLayer());
		addChild(gameLayer);
	}

	public static GameScene make() {
		synchronized (sync_obj) {
			if (instance == null) {
				instance = new GameScene();
				// instance.autoRelease(true);
			}
			return instance;
		}
	}

	public synchronized void startNewGame() {
		gameLayer.initGameLayer(StageManager.instance.currentStage);
	}

	public synchronized void startNewTimeGame() {
		gameLayer.initTimeGame();
	}

	public synchronized void pauseGame() {
		gameLayer.pauseGame();
	}

	public synchronized void resumeGame() {
		gameLayer.resumeGame();
	}

	public synchronized void updateGold() {
		gameLayer.updateGold();
	}

	public synchronized void updateTool() {
		gameLayer.updateTool();
	}

	@Override
	public boolean wyKeyDown(KeyEvent event) {

		if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
			gameLayer.pauseGame();

			// MainScene.make().showMainMenu();
			// GameManager.instance.quitGame();
			// GameUtil.switchSceneFlipX(MainScene.make());
			// ADHelper.hideAd();
			return true;
		}
		return super.wyKeyDown(event);
	}
}
